home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / delays.arc / DELAY.C next >
C/C++ Source or Header  |  1989-07-20  |  5KB  |  204 lines

  1. /* DELAY.C - delays for a given time or until a given time-of-day */
  2.  
  3. /* Copyright 1989 (c) by Robert F. Bohn Jr. (Quickie Software)    */
  4. /*   For more information, contact me via these:                  */
  5. /*      CompuServe 72321,477                                      */
  6. /*      FidoNet    1:236/6.1                                      */
  7. /*   Compiled with QuickC 2.00       07/05/89                     */
  8.  
  9. #include <stdio.h>
  10. #include <graph.h>
  11. #include <ctype.h>
  12. #include <time.h>
  13.  
  14. #define TRUE 1
  15. #define FALSE 0
  16. #define ON 1
  17. #define OFF 0
  18.  
  19.  
  20. #define DEBUG TRUE
  21. #define MAXLEN 133
  22.  
  23.  
  24. void setcurpos(row, col)
  25.   int row, col;
  26. {
  27.   row = ((row>25) ? 25 : row);
  28.   row = ((row< 1) ?  1 : row);
  29.   col = ((col>79) ? 79 : col);
  30.   col = ((col< 1) ?  1 : col);
  31.   _settextposition( (short) row, (short) col );
  32. }
  33.  
  34.  
  35. void display_syntax()
  36. {
  37.   printf("\n");
  38.   printf("       Correct syntax is one of the following:\n");
  39.   printf("\n");
  40.   printf("           DELAY FOR hh HOUrs\n");
  41.   printf("           DELAY FOR mm MINutes\n");
  42.   printf("           DELAY FOR ss SEConds\n");
  43.   printf("           DELAY UNTIL hh:mm\n");
  44.   printf("\n");
  45.   printf(" ╔═══════════════════════════════════════════════════════════╗\n");
  46.   printf(" ║ If you liked this utility, or have suggestions on how to  ║\n");
  47.   printf(" ║ improve it, send a message to Rob Bohn via one of these:  ║\n");
  48.   printf(" ║                    72321,477 CompuServe                   ║\n");
  49.   printf(" ║                     1:236/6.1 FidoNet                     ║\n");
  50.   printf(" ╚═══════════════════════════════════════════════════════════╝\n");
  51.   printf("\n");
  52. }
  53.  
  54.  
  55. main(argc, argv)
  56.  int argc;
  57.  char *argv[];
  58. {
  59.   char *digit1_ptr, *digit2_ptr, *colon_ptr, *digit3_ptr, *digit4_ptr;
  60.   char current_time[9], until_time[9],
  61.        until_hh_s[3], until_mm_s[3], until_ss_s[3];
  62.   struct rccoord oldpos;
  63.   int  time_ok, until_hh, until_mm, until_ss, until_arg;
  64.  
  65.  
  66.   if ( (argc<3) || (argc>4) )
  67.   {
  68.     printf("ERROR:\a you must supply either two or three arguments.\n");
  69.     display_syntax();
  70.     exit(1);
  71.   }
  72.  
  73.   (void) strupr( argv[1] );   /* will upper case arg1, returns ptr as OK flag */
  74.   if ( (strcmp(argv[1], "UNTIL") != 0) &&
  75.        (strcmp(argv[1], "FOR") != 0) )
  76.   {
  77.     printf("ERROR:\a The first argument must be the word 'UNTIL' or 'FOR'.\n");
  78.     display_syntax();
  79.     exit(2);
  80.   }
  81.  
  82.   if (strcmp(argv[1], "UNTIL") == 0)
  83.   {
  84.     time_ok = TRUE;
  85.     if ( !isdigit( *(argv[2]  ) ) )
  86.       time_ok = FALSE;
  87.     if ( !isdigit( *(argv[2]+1) ) )
  88.       time_ok = FALSE;
  89.     if (           *(argv[2]+2) != ':' )
  90.       time_ok = FALSE;
  91.     if ( !isdigit( *(argv[2]+3) ) )
  92.       time_ok = FALSE;
  93.     if ( !isdigit( *(argv[2]+4) ) )
  94.       time_ok = FALSE;
  95.  
  96.     if (time_ok == FALSE)
  97.     {
  98.       printf("ERROR:\a Time must be stated as 'HH:MM' after the word 'UNTIL'.\n");
  99.       display_syntax();
  100.       exit(3);
  101.     }
  102.   }
  103.  
  104.   if (strcmp(argv[1], "FOR") == 0)
  105.   {
  106.     time_ok = TRUE;
  107.     if ( !isdigit( *(argv[2]  ) ) )
  108.       time_ok = FALSE;
  109.     if ( !isdigit( *(argv[2]+1) ) )
  110.       time_ok = FALSE;
  111.  
  112.     if (time_ok == FALSE)
  113.     {
  114.       printf("ERROR:\a Time must be two digits after the word 'FOR'.\n");
  115.       display_syntax();
  116.       exit(4);
  117.     }
  118.     (void) strupr( argv[3] );   /* will upper case arg3, returns ptr as OK flag */
  119.     *(argv[3]+3) = '\0';     /* to set to 3 or less characters */
  120.     if ( (strcmp(argv[3], "HOU") != 0) &&
  121.      (strcmp(argv[3], "MIN") != 0) &&
  122.      (strcmp(argv[3], "SEC") != 0) )
  123.     {
  124.       printf("ERROR:\a The time must be followed by at least the first\n");
  125.       printf("       three letters of the words HOURS, MINUTES, or SECONDS.\n");
  126.       display_syntax();
  127.       exit(5);
  128.     }
  129.   }
  130.  
  131.   _strtime( current_time );
  132.  
  133.   if (strcmp(argv[1], "UNTIL") == 0)
  134.   {
  135.     strcpy(until_time, argv[2]);
  136.     until_time[5] = ':';
  137.     until_time[6] = '0';
  138.     until_time[7] = '0';
  139.     until_time[8] = '\0';
  140.   }
  141.  
  142.   if (strcmp(argv[1], "FOR") == 0)
  143.   {
  144.     strcpy(until_time, current_time);
  145.  
  146.     until_hh_s[0] = until_time[0];
  147.     until_hh_s[1] = until_time[1];
  148.     until_hh_s[2] = '\0';
  149.     until_hh      = atoi(until_hh_s);
  150.  
  151.     until_mm_s[0] = until_time[3];
  152.     until_mm_s[1] = until_time[4];
  153.     until_mm_s[2] = '\0';
  154.     until_mm      = atoi(until_mm_s);
  155.  
  156.     until_ss_s[0] = until_time[6];
  157.     until_ss_s[1] = until_time[7];
  158.     until_ss_s[2] = '\0';
  159.     until_ss      = atoi(until_ss_s);
  160.  
  161.     until_arg  = atoi(argv[2]);
  162.  
  163.     if (strcmp(argv[3], "SEC") == 0)
  164.       until_ss = until_ss + until_arg;
  165.     if (until_ss > 59)
  166.     {
  167.       until_ss -= 60;
  168.       until_mm++;
  169.     }
  170.  
  171.     if (strcmp(argv[3], "MIN") == 0)
  172.       until_mm = until_mm + until_arg;
  173.     if (until_mm > 59)
  174.     {
  175.       until_mm -= 60;
  176.       until_hh++;
  177.     }
  178.  
  179.     if (strcmp(argv[3], "HOU") == 0)
  180.       until_hh = until_hh + until_arg;
  181.     if (until_hh > 23)
  182.       until_hh -= 24;
  183.  
  184.     sprintf( until_time, "%2.2d:%02.2d:%02.2d", until_hh, until_mm, until_ss);
  185.   }
  186.  
  187.   printf("Delay v0.3 - delaying until %s; current time is %s",
  188.     until_time, current_time);
  189.   oldpos = _gettextposition();
  190.  
  191.   while (strcmp(current_time,until_time) != 0)
  192.   {
  193.     _strtime( current_time );
  194.     if (current_time[7] == '0')
  195.     {
  196.       setcurpos(oldpos.row, 55);
  197.       printf("%s",current_time);
  198.     }
  199.   }
  200.  
  201.   printf("\nDelay complete\a");
  202.   exit(0);
  203. }
  204.